<template>
  <div class="search-bar">
    <span class="search-bar__title">
      {{ dataModelBase.titleName || 'XXX' }}审计点
    </span>

    <slot name="auditAttr"></slot>

    <el-form label-suffix="：" label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="审计对象">
            <el-select v-model="prvdInfo" placeholder="请选择">
              <el-option
                v-for="item in selectList.prvdInfo"
                :key="item.value"
                :label="item.label"
                :value="item"
                value-key="value"
              >
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="审计期间">
            <el-date-picker
              v-model="audTrm"
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              placeholder="选择日期"
              :picker-options="pickerOptions"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import widget from '@/mixins/widget'

export default {
  mixins: [widget],
  data() {
    return {
      prvdInfo: {},
      audTrm: ['', ''],
      selectList: {
        // 审计对象
        prvdInfo: []
      },
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now() - 8.64e6
        }
      }
    }
  },

  computed: {
    params() {
      return {
        prvdInfo: this.prvdInfo,
        audTrmStart: this.audTrm[0],
        audTrmEnd: this.audTrm[1]
      }
    }
  },

  watch: {
    params: {
      deep: true,
      handler(newValue) {
        this.$emit('change', newValue)
      }
    }
  },

  methods: {
    async getData() {
      const res = await this.httpRequest()
      this.selectList.prvdInfo = res.prvdInfo

      this.prvdInfo = this.selectList.prvdInfo[0]
    },
    findPrvdInfo(label, value, initVal) {
      return this.selectList.prvdInfo.filter(item => {
        if (label) return item.label === label
        if (value) return item.value === value
        if (initVal) this.prvdInfo = this.selectList.prvdInfo[0]
      })[0]
    }
  }
}
</script>

<style lang="scss" scoped>
.search-bar {
  height: 66px;
  display: flex;
  align-items: center;
  border-radius: 4px;
  box-shadow: 0 0 11px 0 rgba(148, 166, 212, 0.26);
  background-color: #fff;
  overflow: hidden;
  &::before {
    content: '';
    display: block;
    width: 5px;
    height: 100%;
    margin-right: 12px;
    background: #3d63b0;
  }
  &__title {
    font-weight: bold;
    min-width: 100px;
    margin-right: 20px;
  }
  .el-select,
  .el-input {
    width: 60%;
  }
  .el-date-editor {
    width: 90%;
  }
  .el-button {
    margin-left: 26px;
  }
  .el-form {
    margin-left: 128px;
    &-item {
      margin-bottom: 0;
    }
  }
}
</style>
